'''
class Solution {
    public int uniquePaths(int m, int n) {
        // dp[i][j]表示从（0,0）到（i,j）路径数量
        int[][] dp=new int[m][n];
        // 初始化
        // 只能向右
        for(int j=0; j<n; j++){
            dp[0][j]=1;
        }
        // 只能向下
        for (int i=0; i<m; i++){
            dp[i][0]=1;
        }
        for (int i=1; i<m; i++){
            for (int j=1; j<n; j++){
                dp[i][j] = dp[i-1][j]+dp[i][j-1];
            }
        }
        return dp[m-1][n-1];
    }
}
'''
class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        dp = [[0 for _ in range(n)] for _ in range(m)]
        for i in range(m):
            dp[i][0] = 1
        for j in range(n):
            dp[0][j] = 1
        for i in range(1,m):
            for j in range(1,n):
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
        return dp[m-1][n-1]


class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        import math
        N = m+n-2
        M = min(m-1,n-1)
        return math.factorial(N)//(math.factorial(M)*math.factorial(N-M))
'''
排列组合 // 为了让输出的不带小数点
'''

